home *** CD-ROM | disk | FTP | other *** search
/ PC Open 101 / PC Open 101 CD 2.bin / CD2 / PDF / Corsi / PHP / lezione_1 / check.php < prev    next >
Encoding:
PHP Script  |  2004-10-01  |  1.0 KB  |  32 lines

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2.  
  3. <html>
  4. <head>
  5.     <title>Foreach come controllo</title>
  6. </head>
  7. <body>
  8. <h4>Compila tutti i campi:</h4><p>
  9. <form action="check.php" method="post">
  10. <input name="nome" type="text" size="20"> Nome<p>
  11. <input name="cognome" type="text" size="20"> Cognome<p>
  12. <input name="citt" type="text" size="20"> Cittα<p>
  13. <input type="submit" value="invia">
  14. </form>
  15.     <?php
  16.     if (!isset($_POST['nome'])) {
  17.     // serve solo alla prima chiamata della pagina
  18.             die ("<p><h3>Tutti i campi vanno obbligatoriamente compilati</h3>");
  19.         }
  20.     foreach ($_POST as $ctr) {
  21.     // foreach ci consente di controllare tutto l'array $_POST
  22.         if (trim($ctr)==""){
  23.         // trim toglie gli spazi vuoti eventualmente presenti in $ctr
  24.             die ("<p><h3>Tutti i campi vanno obbligatoriamente compilati</h3>");
  25.         }
  26.     }        
  27.                 echo "<p><h4>ciao ".$_POST['nome']." ".$_POST['cognome'].", vivi a ".$_POST['citt'].". Come stai?</h4>";
  28.         
  29.     ?>
  30. </body>
  31. </html>
  32.